package com.sporadic.backstage.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sporadic.backstage.entity.Dishes;
import com.sporadic.backstage.entity.DishesType;
import com.sporadic.backstage.service.DishesTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@CrossOrigin(origins = {"http://localhost:8080"}, methods = {RequestMethod.GET, RequestMethod.POST}, allowCredentials = "true")
@Controller
public class DishesTypeController {
    @Autowired
    private DishesTypeService dishesTypeService;

    /**
     * 查询商家所有菜品类型
     * @param merchantId 商家编号
     * @return 类型信息集合
     */
    @ResponseBody
    @RequestMapping("/selDishesTypeAll")
    public List<DishesType> selDishesTypeAll(Integer merchantId) {
        return dishesTypeService.selDishesTypeAlL(merchantId);
    }

    /**
     * 分页查询菜品类型
     * @param map 条件信息
     * @return 分页信息
     */
    @RequestMapping("/selDishesType")
    @ResponseBody
    IPage<DishesType> selDishesType(@RequestBody Map<String,Object> map){
        Page<Dishes> page=new Page<>();
        page.setCurrent((Integer) map.get("current"));
        page.setSize((Integer) map.get("pageSize"));
        return dishesTypeService.selDishesType(page,(Integer)map.get("merchantId"));
    }
    /**
     * 添加指定商家菜品类型
     * @param dishestype 菜品类型信息
     * @return 受影响行数 大于0添加成功 否则失败
     */
    @ResponseBody
    @RequestMapping("/addDishesType")
    public Integer addDishesType(DishesType dishestype) {
        return dishesTypeService.addDishesType(dishestype);
    }

    /**
     * 删除指定商家菜品指定类型
     * @param merchantId 商家编号
     * @param dtId 菜品类型编号
     * @return
     */
    @ResponseBody
    @RequestMapping("/delDishesType")
    public Integer delDishesType(@RequestParam("merchantId") Integer merchantId,@RequestParam("dtId") Integer dtId) {
        return dishesTypeService.delDishesType(merchantId, dtId);
    }

    /**
     * 根据商家编号修改指定商家菜品类型
     * @param dishestype
     * @return
     */
    @ResponseBody
    @RequestMapping("/upDishesType")
    public Integer upDishesType(DishesType dishestype) {
        return dishesTypeService.upDishesType(dishestype);
    }
}
